package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.JtProductCategory;
import com.ruoyi.common.annotation.RepeatSubmit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtWarehouse;
import com.ruoyi.business.service.IJtWarehouseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-29
 */
@Controller
@RequestMapping("/business/warehouse")
public class JtWarehouseController extends BaseController
{
    private String prefix = "business/warehouse";

    @Autowired
    private IJtWarehouseService jtWarehouseService;

    @RequiresPermissions("business:warehouse:view")
    @GetMapping()
    public String warehouse()
    {
        return prefix + "/warehouse";
    }

    /**
     * 查询仓库列表
     */
    @RequiresPermissions("business:warehouse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtWarehouse jtWarehouse)
    {
        startPage();
        List<JtWarehouse> list = jtWarehouseService.selectJtWarehouseList(jtWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出仓库列表
     */
    @RequiresPermissions("business:warehouse:export")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtWarehouse jtWarehouse)
    {
        List<JtWarehouse> list = jtWarehouseService.selectJtWarehouseList(jtWarehouse);
        ExcelUtil<JtWarehouse> util = new ExcelUtil<JtWarehouse>(JtWarehouse.class);
        return util.exportExcel(list, "仓库数据");
    }

    /**
     * 新增仓库
     */
    @RequiresPermissions("business:warehouse:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仓库
     */
    @RequiresPermissions("business:warehouse:add")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult addSave(JtWarehouse jtWarehouse)
    {
        return toAjax(jtWarehouseService.insertJtWarehouse(jtWarehouse));
    }

    /**
     * 修改仓库
     */
    @RequiresPermissions("business:warehouse:edit")
    @GetMapping("/edit/{warehouseId}")
    public String edit(@PathVariable("warehouseId") Long warehouseId, ModelMap mmap)
    {
        JtWarehouse jtWarehouse = jtWarehouseService.selectJtWarehouseByWarehouseId(warehouseId);
        mmap.put("jtWarehouse", jtWarehouse);
        return prefix + "/edit";
    }

    /**
     * 修改保存仓库
     */
    @RequiresPermissions("business:warehouse:edit")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtWarehouse jtWarehouse)
    {
        return toAjax(jtWarehouseService.updateJtWarehouse(jtWarehouse));
    }

    /**
     * 删除仓库
     */
    @RequiresPermissions("business:warehouse:remove")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtWarehouseService.deleteJtWarehouseByWarehouseIds(ids));
    }

    /**
     * 查询仓库列表
     */
    @GetMapping("/select/list")
    @ResponseBody
    public AjaxResult selectList()
    {
        JtWarehouse param = new JtWarehouse();
        param.setStatus(0);
        List<JtWarehouse> list = jtWarehouseService.selectJtWarehouseList(param);

        AjaxResult ajax = new AjaxResult();
        ajax.put("code", 200);
        ajax.put("value", list);
        return ajax;
    }
}
